package mspbots.cw.client.core.data.callbacks;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.List;

/**
 * com.mspbots.sync.callback.CallBackController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/10/9
 */
@Log4j2
@RequiredArgsConstructor
@RestController
@RequestMapping("callbacks/{tenant}")
public class CallBacksController {

    private final CallbacksServiceImpl callbacksService;

    @GetMapping
    public Flux<JsonNode> get(@PathVariable Long tenant) {
        return this.callbacksService.get(tenant);
    }

    @PostMapping
    public Flux<JsonNode> add(@PathVariable Long tenant) {
        return this.callbacksService.post(tenant);
    }

    @PostMapping("batch")
    public Flux<JsonNode> batchAdd(@PathVariable Long tenant, @Valid @RequestBody List<CallbackParam> params) {
        return this.callbacksService.batchAdd(tenant, params);
    }

    @DeleteMapping
    public Flux<JsonNode> delete(@PathVariable Long tenant) {
        return this.callbacksService.delete(tenant);
    }

    @PutMapping("{id}")
    public Mono<Object> modify(@PathVariable Long tenant, @PathVariable int id,
                               @Valid @RequestBody CallbackParam body) {
        return this.callbacksService.put(tenant, id, body);
    }


}
